//=========================================================================
// Copyright (C) 2023 The C++ Component Model(COMO) Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//=========================================================================

#ifndef __CZMQUTILS_H__
#define __CZMQUTILS_H__

typedef signed char     Byte;
typedef short           Short;
typedef int             Integer;
typedef long long int   Long;
typedef float           Float;
typedef double          Double;
typedef char32_t        Char;
typedef bool            Boolean;
typedef uintptr_t       HANDLE;
typedef int             ECode;

constexpr Integer RPC_MAGIC_NUMBER = 0x7a79636f;

#pragma pack(1)
typedef struct tagCOMO_ZMQ_RPC_MSG_HEAD {
    HANDLE  hChannel;   // mServerObjectId
    Integer eCode;      // eventCode(ZmqFunCode), ECode
    Long crc64;         // crc_64_ecma(reinterpret_cast<const unsigned char *>(buf), bufSize);
    Integer msgSize;
} COMO_ZMQ_RPC_MSG_HEAD;

typedef struct tagCOMO_ZMQ_RPC_MSG_BODY {
    Integer RPC_MAGIC_NUMBER;   //
    Integer mIndex;             // interfaceIndex
    Integer methodIndex_4;      // methodIndex + 4
    Long uuid64;                // macAddress:32, millisecond:32
    Byte arguments[];
} COMO_ZMQ_RPC_MSG_BODY;
#pragma pack()

Integer CheckCOMO_ZMQ_RPC_MSG(const unsigned char *input_str, size_t num_bytes);
Integer GenCOMO_ZMQ_RPC_MSG(unsigned char *input_str, size_t num_bytes);

#endif // __CZMQUTILS_H__
